home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 11 / Cream of the Crop 11-2.iso / extra / disp186b.zip / STEALTH.ASM < prev    next >
Assembly Source File  |  1992-08-12  |  13KB  |  434 lines

  1. ;--------------------------------------------------------------------------
  2. ; This is file STEALTH.ASM
  3. ;
  4. ; Copyright (C) 1991 DJ Delorie, 24 Kirsten Ave, Rochester NH 03867-2954
  5. ; Copyright (C) 1992 Csaba Biegl, 820 Stirrup Dr, Nashville, TN 37221
  6. ;
  7. ; This file is distributed under the terms listed in the document
  8. ; "copying.dj", available from DJ Delorie at the address above.
  9. ; A copy of "copying.dj" should accompany this file; if not, a copy
  10. ; should be available from where this file was obtained.  This file
  11. ; may not be distributed without a verbatim copy of "copying.dj".
  12. ;
  13. ; This file is distributed WITHOUT ANY WARRANTY; without even the implied
  14. ; warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. ;--------------------------------------------------------------------------
  16.  
  17. _TEXT    segment byte public 'CODE'
  18. _TEXT    ends
  19. DGROUP  group    _TEXT,_DATA,_BSS
  20.     assume  cs:_TEXT,ds:DGROUP
  21. _DATA    segment word public 'DATA'
  22. d@    label    byte
  23. d@w    label    word
  24. _DATA    ends
  25. _BSS    segment word public 'BSS'
  26. b@    label    byte
  27. b@w    label    word
  28. _BSS    ends
  29. _TEXT    segment byte public 'CODE'
  30.     assume  cs:_TEXT,ds:DGROUP
  31.  
  32. include grdriver.inc
  33.  
  34. ;--------------------------------------------------------------------------
  35. ; DRIVER HEADER
  36. ;  The following entries MUST match the structure and constant
  37. ;  declarations in the file 'grdriver.h' of the GRX graphics library
  38. ;  The mode word should contain the following bitfields:
  39. ;     - the GRD_NEW_DRIVER bit set for any new format driver
  40. ;     - the adapter type field should be specified
  41. ;     - the memory size field should be specified
  42. ;     - the paging mode field should be specified
  43. ;  The mode set routine will OR in the plane bitfield as it will
  44. ;  change when different color number modes are requested.
  45. ;--------------------------------------------------------------------------
  46.  
  47.     dw    offset mode_set_routine
  48.     dw    offset paging_routine
  49. mode_W  dw    GRD_NEW_DRIVER+GRD_VGA+GRD_1024K+GRD_NO_RW
  50. ;
  51. ; The 'def_xx' fields are filled in by go32 from the corresponding
  52. ; fields of the 'GO32' environment variable
  53. ;
  54. def_tw  dw    80        ; text width
  55. def_th  dw    25        ; text height
  56. def_gw  dw    320        ; graphics width
  57. def_gh  dw    200        ; graphics height
  58. def_nc  dw    16        ; graphics colors
  59.     dw    offset driver_init_routine
  60.     dw    offset text_mode_table
  61.     dw    offset graphics_mode_table
  62.  
  63. ;
  64. ; Biggest text and graphics sizes
  65. ;
  66. Max_TW  equ    80
  67. Max_TH  equ    50
  68. Max_GWn equ    640        ; non interlaced!!!
  69. Max_GHn equ    480
  70. Max_GW  equ    640        ; may be interlaced
  71. Max_GH  equ    480
  72.  
  73.  
  74. ;--------------------------------------------------------------------------
  75. ; TABLE OF SUPPORTED TEXT MODES
  76. ;    - keep sorted by size
  77. ;    - end with an all 0 entry
  78. ;    - BIOS field = 0xff disables it
  79. ;    - fields:
  80. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  81. ;--------------------------------------------------------------------------
  82. text_mode_table        label word
  83.     dw    80,    25,    2,    007h +  00000h
  84.     dw    40,    25,    16,    001h +  00000h
  85.     dw    80,    25,    16,    003h +  00000h
  86.     dw    80,    50,    16,    003h +  00300h
  87.     dw    132,    25,    16,    009h +  00100h  ; VESA 10ah mode
  88.     dw    132,    44,    16,    00ah +  00100h  ; VESA 10ah mode
  89.     dw    0,    0,    0,    000h +  00000h
  90.  
  91. ;--------------------------------------------------------------------------
  92. ; TABLE OF SUPPORTED GRAPHICS MODES
  93. ;    - keep sorted first by colors then by size
  94. ;    - end with an all 0 entry
  95. ;    - BIOS field = 0xff disables it
  96. ;    - fields:
  97. ;        width,  height, colors, BIOS#+  setup_procedure_index*256
  98. ;--------------------------------------------------------------------------
  99. graphics_mode_table    label word
  100.     dw    320,    200,    16,    00dh +  00000h
  101.     dw    640,    200,    16,    00eh +  00000h
  102.     dw    640,    350,    16,    010h +  00000h
  103.     dw    640,    480,    16,    012h +  00000h
  104.     dw    800,    600,    16,    002h +  00100h  ; VESA 102h mode
  105.     dw    320,    200,    256,    013h +  00000h
  106.     dw    640,    480,    256,    001h +  00200h  ; VESA S3 201h mode
  107.     dw    800,    600,    256,    003h +  00200h  ; VESA S3 203h mode
  108.     dw     1024,    768,    256,    005h +  00200h  ; VESA S3 205h mode
  109.     dw    0,    0,    0,    000h +  00000h
  110.  
  111. ;--------------------------------------------------------------------------
  112. ; TABLE OF SPECIAL SETUP PROCEDURES
  113. ;  You may need such procedures for:
  114. ;     -- reloading fonts on standard EGA or VGA for
  115. ;     higher resolution text modes
  116. ;     -- enable HiColor mode of some Super VGAs
  117. ;     -- Handle the parameter passing conventions of the VESA BIOS
  118. ;     -- put VGA into 256 color plane mode ("MODE X")
  119. ;     -- etc...
  120. ;  There should be one entry in the table for every non-zero
  121. ;  'setup_procedure_index' in the text and graphics mode tables.
  122. ;  The first entry in the table belongs to index 100h, and so on.
  123. ;  The special setup procedure is invoked via a near call.
  124. ;
  125. ;  Entry: DI=address of the mode record from the text or graphics
  126. ;      table to set up.
  127. ;
  128. ;  Exit:  Adapter configured
  129. ;      BX=driver mode word as it should be returned by the mode set
  130. ;         routine. Typically it involves picking up the mode word
  131. ;         from the header and OR-ing in the appropriate bitplane mode
  132. ;         bitfield. (This is not needed for text modes)
  133. ;      AX, CX, DX, SI can be trashed, PRESERVE DI!!!!
  134. ;
  135. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  136. ;--------------------------------------------------------------------------
  137. special_setup_table    label word
  138.     dw    offset  VESA_SVGA_mode_set    ; for 01xxh modes
  139.     dw    offset  VESA_S3_mode_set    ; for 02xxh modes
  140.     dw    offset  VGA_50_row_mode_set
  141.  
  142. ;
  143. ; Routine to set up VGA 50 row mode
  144. ; interface is described above
  145. ;
  146. VGA_50_row_mode_set    proc    near
  147.     mov    ax,03h            ; set 80x25 mode
  148.     int    10h
  149.     xor    bx,bx
  150.     mov    ax,1112h        ; load 8x8 font
  151.     int    10h
  152.     ret
  153. VGA_50_row_mode_set    endp
  154.  
  155. ;
  156. ; Routine to set up VESA SVGA modes
  157. ; only used for 16 color text and graphics modes
  158. ; interface is described above
  159. ;
  160. VESA_SVGA_mode_set    proc    near
  161.     mov    ax,4f02h
  162.     mov    bx,WORD PTR [di+6]
  163.     int    10h
  164.     mov    bx,0ffffh        ; error code
  165.     cmp    ax,004fh
  166.     jne    VESA_SVGA_error
  167.     mov    bx,mode_W
  168.     or    bx,GRD_4_PLANES
  169. VESA_SVGA_error:
  170.     ret
  171. VESA_SVGA_mode_set    endp
  172.  
  173. ; Routine to set up VESA S3 modes
  174. ; only used for 256 color graphics modes
  175. ; interface is described above
  176. ;
  177. VESA_S3_mode_set    proc    near
  178.     mov    ax,4f02h
  179.     mov    bx,WORD PTR [di+6]
  180.     int    10h
  181.     mov    bx,0ffffh        ; error code
  182.     cmp    ax,004fh
  183.     jne    VESA_S3_error
  184.     mov    bx,mode_W
  185.     xor    bx,(GRD_VGA XOR GRD_S3)
  186.     or    bx,GRD_8_PLANES
  187. VESA_S3_error:
  188.     ret
  189. VESA_S3_mode_set    endp
  190.  
  191.  
  192. ;--------------------------------------------------------------------------
  193. ; DRIVER INIT ROUTINE
  194. ;  called once after the driver is loaded
  195. ;  may do one or more of the followings:
  196. ;    - check for proper board type
  197. ;    - check amount of RAM on board, and:
  198. ;    -- update word in header to reflect correct amount
  199. ;    -- disable modes in the tables for which there is not enough RAM
  200. ;    - check for special equipment (HiColor DAC, etc...)
  201. ;
  202. ;  Entry: nothing
  203. ;
  204. ;  Exit:  AX=status:
  205. ;       non-zero: OK,
  206. ;       0: something went wrong (e.g. wrong adapter, etc..)
  207. ;      BX,CX,DX may be trashed
  208. ;
  209. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  210. ;--------------------------------------------------------------------------
  211. driver_init_routine    proc    far
  212.     push    di
  213.     push    es
  214.     sub    sp,256
  215.     mov    di,sp
  216.     mov    ax,ss
  217.     mov    es,ax
  218.     mov    ax,4f00h
  219.     int    10h        ; check for VESA BIOS
  220.     cmp    ax,004fh
  221.     jne    init_error
  222.     cmp    BYTE PTR es:[di+0],'V'
  223.     jne    init_error
  224.     cmp    BYTE PTR es:[di+1],'E'
  225.     jne    init_error
  226.     cmp    BYTE PTR es:[di+2],'S'
  227.     jne    init_error
  228.     cmp    BYTE PTR es:[di+3],'A'
  229.     jne    init_error
  230.     mov    ax,1        ; OK, VESA BIOS found
  231.     jmp    init_done
  232. init_error:
  233.     xor    ax,ax
  234. init_done:
  235.     add    sp,256
  236.     pop    es
  237.     pop    di
  238.     ret
  239. driver_init_routine    endp
  240.  
  241.  
  242. ;--------------------------------------------------------------------------
  243. ; MODE SET ROUTINE
  244. ;  sets up a text or graphics mode as close as possible to the one
  245. ;  reguested by the user with regard to number of colors and size.
  246. ;
  247. ;  Entry: AX=mode selection
  248. ;     0 = 80x25 text
  249. ;     1 = default text
  250. ;     2 = text CX cols by DX rows
  251. ;     3 = biggest text
  252. ;     4 = 320x200 graphics
  253. ;     5 = default graphics
  254. ;     6 = graphics CX width by DX height
  255. ;     7 = biggest non-interlaced graphics
  256. ;     8 = biggest graphics
  257. ;     9 = graphics BX colors, CX width by DX height
  258. ;
  259. ;  Exit: BX=driver mode flag
  260. ;     CX=width (in pixels or characters)
  261. ;     DX=height
  262. ;
  263. ;  NOTE: This runs in real mode, but don't mess with the segment registers.
  264. ;     YOU SHOULD NOT NEED TO CHANGE THIS ROUTINE AS IT IS PRETTY
  265. ;     MUCH TABLE DRIVEN
  266. ;--------------------------------------------------------------------------
  267. mode_set_routine    proc    far
  268.     push    ds
  269.     push    di
  270.     push    si
  271.     mov    si,cs
  272.     mov    ds,si
  273.     cmp    ax,9
  274.     jbe    DoIt
  275.     jmp    Exit
  276. DoIt:    add    ax,ax
  277.     mov    si,ax
  278.     jmp    WORD PTR mode_set_table[si]
  279. mode_set_table  label    word
  280.     dw    offset mode_0
  281.     dw    offset mode_1
  282.     dw    offset mode_2
  283.     dw    offset mode_3
  284.     dw    offset mode_4
  285.     dw    offset mode_5
  286.     dw    offset mode_6
  287.     dw    offset mode_7
  288.     dw    offset mode_8
  289.     dw    offset mode_9
  290. mode_0: mov    si,offset text_mode_table    ; 80x25 text
  291.     mov    bx,def_nc
  292.     mov    cx,80
  293.     mov    dx,25
  294.     jmp    Lookup
  295. mode_1: mov    si,offset text_mode_table    ; default text
  296.     mov    bx,def_nc
  297.     mov    cx,def_tw
  298.     mov    dx,def_th
  299.     jmp    Lookup
  300. mode_2: mov    si,offset text_mode_table    ; CX*DX text
  301.     mov    bx,def_nc
  302.     jmp    Lookup
  303. mode_3: mov    si,offset text_mode_table    ; biggest text
  304.     mov    bx,def_nc
  305.     mov    cx,Max_TW
  306.     mov    dx,Max_TH
  307.     jmp    Lookup
  308. mode_4: mov    si,offset graphics_mode_table    ; 320x200 graphics
  309.     mov    bx,def_nc
  310.     mov    cx,320
  311.     mov    dx,200
  312.     jmp    Lookup
  313. mode_5: mov    si,offset graphics_mode_table    ; default graphics
  314.     mov    bx,def_nc
  315.     mov    cx,def_gw
  316.     mov    dx,def_gh
  317.     jmp    Lookup
  318. mode_6: mov    si,offset graphics_mode_table    ; CX*DX graphics
  319.     mov    bx,def_nc
  320.     jmp    Lookup
  321. mode_7: mov    si,offset graphics_mode_table    ; biggest non-interlaced gr
  322.     mov    bx,def_nc
  323.     mov    cx,Max_GWn
  324.     mov    dx,Max_GHn
  325.     jmp    Lookup
  326. mode_8: mov    si,offset graphics_mode_table    ; biggest graphics
  327.     mov    bx,def_nc
  328.     mov    cx,Max_GW
  329.     mov    dx,Max_GH
  330.     jmp    Lookup
  331. mode_9: mov    si,offset graphics_mode_table    ; CX*DX graphics w/ BX colors
  332. ;
  333. ; At this point:
  334. ;   SI points to the table to search (text or graphics)
  335. ;   BX has colors
  336. ;   CX has width
  337. ;   DX has height
  338. ;
  339. Lookup: xor    ax,ax                ; last color number seen
  340. Find_C: cmp    [si+4],ax            ; last color number == this?
  341.     je    Same_C
  342.     jb    Prev_C                ; end of table -- use last color
  343.     cmp    BYTE PTR [si+6],0ffh        ; valid entry ?
  344.     je    Prev_C                ; not -- use last color
  345.     mov    ax,[si+4]            ; record color number
  346.     mov    di,si                ; start of entries w/ this color
  347.     cmp    ax,bx                ; enough colors ?
  348.     jae    Find_S
  349. Same_C: add    si,8
  350.     jmp    Find_C
  351. Prev_C: or    ax,ax                ; found any color at all?
  352.     je    Exit
  353. ;
  354. ; At this point:
  355. ;   DI points into the table to the first entry with the desired color
  356. ;      number (either it has enough colors or it is the highest color
  357. ;      number supported by the driver). Additionally, at least the
  358. ;      first (= smallest size) entry for this color is valid (has a
  359. ;      valid BIOS number).
  360. ;   AX has the color number adjusted for the driver
  361. ;   CX has width
  362. ;   DX has height
  363. ;
  364. Find_S: cmp    [di+4],ax            ; still the same color #?
  365.     jne    Prev_S
  366.     cmp    BYTE PTR [di+6],0ffh        ; valid entry ?
  367.     je    Prev_S
  368.     cmp    [di],cx
  369.     jb    Next_S
  370.     cmp    [di+2],dx
  371.     jae    GotIt
  372. Next_S: add    di,8
  373.     jmp    Find_S
  374. Prev_S: sub    di,8
  375. ;
  376. ; At this point:
  377. ;   DI points to the table entry we want to set up
  378. ;
  379. GotIt:  mov    ax,[di+6]            ; BIOS mode number
  380.     or    ah,ah                ; special ?
  381.     je    doBIOS
  382.     mov    al,ah
  383.     xor    ah,ah
  384.     dec    ax
  385.     add    ax,ax
  386.     mov    si,ax
  387.     call    WORD PTR special_setup_table[si]
  388.     jmp    RetVal
  389. doBIOS: int    10h
  390.     mov    bx,GRD_1_PLANE
  391.     cmp    WORD PTR [di+4],2        ; 2 colors ?
  392.     je    doFLAG
  393.     mov    bx,GRD_4_PLANES
  394.     cmp    WORD PTR [di+4],16        ; 16 colors ?
  395.     je    doFLAG
  396.     mov    bx,GRD_8_PLANES
  397.     cmp    WORD PTR [di+4],256        ; 256 colors ?
  398.     je    doFLAG
  399.     mov    bx,GRD_16_PLANES
  400.     cmp    WORD PTR [di+4],32768        ; 32K colors ?
  401.     je    doFLAG
  402.     mov    bx,GRD_PLANE_MASK        ; something is wrong!!
  403. doFLAG: or    bx,mode_W
  404. RetVal: mov    cx,[di]
  405.     mov    dx,[di+2]
  406. Exit:    pop    si
  407.     pop    di
  408.     pop    ds
  409.     ret
  410. mode_set_routine    endp
  411.  
  412.  
  413. ;--------------------------------------------------------------------------
  414. ; PAGING ROUTINE
  415. ;
  416. ;  Entry: AH=read page
  417. ;      AL=write page
  418. ;
  419. ;  Exit: VGA configured.
  420. ;     AX,BX,CX,DX,SI,DI may be trashed
  421. ;
  422. ;  NOTE: This runs in protected mode!  Don't mess with the segment registers!
  423. ;     This code must be relocatable and may not reference any data!
  424. ;--------------------------------------------------------------------------
  425.     assume  ds:nothing, es:nothing
  426.  
  427. paging_routine  proc    far
  428.     ret
  429. paging_routine  endp
  430.  
  431. _TEXT    ends
  432.     end
  433.  
  434.